#!/usr/bin/ruby
require 'rubygems'
require 'dbaccess.rb'
require 'standardquote.rb'
require 'historicalquote.rb'
require 'perf.rb'
require 'xmlparse.rb'

unless (ARGV.length == 0)
  puts "Usage: setup.rb - run this command to initialize everything for the first time. "
end

x = XmlParse.new("config.xml")
p = x.getparams()
hostname = p["hostname"]
user = p["user"]
pass = p["pass"]
dbname = p["dbname"]

dbobj = DbAccess.new(hostname, user, pass, dbname)
puts "Initializing databases..."
dbobj.createnew()
puts "Done."

puts "Loading symbols..."
dbobj.loadsymbols("../data/NASDAQ.txt", "NASDAQ")
dbobj.loadsymbols("../data/NYSE.txt", "NYSE")
puts "Done."

ex = ["NASDAQ", "NYSE"]
sd = Date.parse("01-01-2008")
ex.each do |exchange|
  quotes = HistoricalQuote.new(hostname, user, pass, dbname)
  puts "Loading historical data for exchange #{exchange}..."
  quotes.loadhistoricaldata(sd.to_s, exchange)
end

ex.each do |exchange|
  quotes = StandardQuote.new(hostname, user, pass, dbname)
  puts "Loading Standard quotes for exchange #{exchange}..."
  quotes.loadexchange(exchange)
  quotes.close()
end

ex.each do |exchange|
  p = Perf.new(hostname, user, pass, dbname)
  puts "Computing performance for exchange #{exchange}..."
  p.generateperf(exchange)
  p.close()
end
